<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>基本信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript" src="${ctxScript}/farm/farm.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			function inputCheck(){
				$(".checkInput").each(function (index,item) {
					let $item=$(item);
					let val=$item.val();
					if(!val){
						$item.removeClass("required");
						$item.attr("readonly",true);
						$item.next().attr("checked",true)
					}

				})
			}
			if('${farm.id}'){
				inputCheck();
			}


			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});


        // function check(checkbox2Id,inputId){
        //
        //     var input=$("#"+inputId);
        //     if('#'+checkbox2Id.attr('checked')){
        //         input.val();
        //         input.attr("readOnly",true);
        //     }
        //
        // }

		function stuYN(checkboxId,textId) {
			var text=$('#'+textId);
			if($("#"+checkboxId).attr("checked")){
				text.val("");
				text.attr("readOnly",true);
				text.attr("class","");
				text.blur();
			}else {
				text.attr("readOnly",false);
			}




			// if (document.getElementById("True").checked == true)     //判断单选框此时状态为未选-
			// {
			// 	document.getElementById("breedCode").readOnly = true;// 文本框可编辑
			// 	 // document.getElementById("1").checked=false; //改变状态
			//
			//
			// 	document.getElementById("breedCode").value=""
			// } else{        //判断单选框此时状态为已选
			// 	// document.getElementById(" ").checked = false;//改变状态
			// 	document.getElementById("breedCode").readOnly = false;// 文本框可编辑
			// }
		}

	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/test2/farm/">基本信息列表</a></li>
		<li class="active"><a href="${ctx}/test2/farm/form?id=${farm.id}">基本信息<shiro:hasPermission name="test2:farm:edit">${not empty farm.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="test2:farm:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="farm" action="${ctx}/test2/farm/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<legend>基本信息</legend>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				养殖类型：<input type="radio" name="farmType"  ${farm.farmType==1 ? 'checked':''} value="1" class="required"/>散养户

						<input type="radio" name="farmType" ${farm.farmType==0 ? 'checked':''} value="0" class="required"/>养殖场
			</div>
		</div>


		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				养殖场名称：<input type="text" name="farmName"  value="${farm.farmName}" class="required"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span class="help-inline"><font color="red">*</font> </span>
				负责人姓名：<input type="text" name="name" value="${farm.name}" class="required"/>
			</div>
		</div>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				负责人身份证号：<input type="text" name="idcard" class="required" value="${farm.idcard}"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span class="help-inline"><font color="red">*</font> </span>
				负责人手机号：<input type="text" name="phone" class="required" value="${farm.phone}"/>
			</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				详细地址：<input type="text" name="address" style="width: 50%" placeholder="请填写村(屯)或门牌号" class="required" value="${farm.address}" />
			</div>
		</div>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				畜禽养殖代码： 	<input type="text" name="breedCode" id="breedCode"  class="required checkInput"   value="${farm.breedCode}"/>&nbsp;
								<input type="checkbox" name="breedCode1" id="one"  value=""  onchange="stuYN('one','breedCode')" />无 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<span class="help-inline"><font color="red">*</font> </span>
				统一社会信用代码： <input type="text" name="creditCode" id="creditCode" value="${farm.creditCode}"  class="required checkInput"/>&nbsp;
								<input type="checkbox" name="creditCode1" id="two" onchange="stuYN('two','creditCode')" />无
			</div>
		</div>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				动物防疫条件许可证号：<input type="text" name="animalCertificate" id="animalCertificate" class="required checkInput" value="${farm.animalCertificate}"/>&nbsp;
									<input type="checkbox"  name="animalCertificate1" id="three" onchange="stuYN('three','animalCertificate')"/>无 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span class="help-inline"><font color="red">*</font> </span>
				种蓄经营许可证号：<input type="text" name="businessCertificate" id="businessCertificate" class="required checkInput" value="${farm.businessCertificate}"/>&nbsp;
								<input type="checkbox" name="businessCertificate1" id="four" onchange="stuYN('four','businessCertificate')"/>无
			</div>
		</div>


		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				排污许可证号：<input type="text" name="pollutantDischargingLicense" id="pollutantDischargingLicense" readonly="${empty farm.pollutantDischargingLicense}" class="required" value="${farm.pollutantDischargingLicense}"/>&nbsp;
							<input type="checkbox" name="pollutantDischargingLicense1" id="five"  checked="${empty farm.pollutantDischargingLicense}" onchange="stuYN('five','pollutantDischargingLicense')" />无 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span class="help-inline"><font color="red">*</font> </span>
				是否环评：<input type="radio" name="environmentalFlag" ${farm.environmentalFlag==2 ? 'checked':''} value="2" class="required"/>环评报告书 &nbsp;
						<input type="radio" name="environmentalFlag" ${farm.environmentalFlag==1 ? 'checked':''} value="1" class="required"/>环评登记表 &nbsp;
						<input type="radio" name="environmentalFlag" ${farm.environmentalFlag==0 ? 'checked':''} value="0" class="required"/>无
			</div>
		</div>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				是否存在违建用房： <input type="radio" name="violateFlag" ${farm.violateFlag==1 ? 'checked':''} value="1" class="required"/>是 &nbsp;
				 				<input type="radio" name="violateFlag" ${farm.violateFlag==0 ? 'checked':''} value="0" class="required"/>否
			</div>
		</div>

		<div class="control-group">
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
				粪污处理设施：<select name="handleFacilities" class="required" >
							<option value="">请选择</option>
							<option value="zhangsan" <c:if test="${'zhangsan' eq (farm.handleFacilities)}">selected</c:if>>zhangsan</option>
							<option value="lisi" <c:if test="${'lisi' eq (farm.handleFacilities)}">selected</c:if>>lisi</option>
							<option value="wangwu" <c:if test="${'wangwu' eq (farm.handleFacilities)}">selected</c:if>>wangwu</option>
							</select>
			</div>
		</div>


	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>


		<ul class="ul-form">
			<li style="width:18%"><label>养殖品种：</label>
				<input type="checkbox" id="pig" name="breedLivestock" onclick="check('pig','breed_livestock')">猪 &nbsp;&nbsp;
				<input type="checkbox" id="cattle" name="breedLivestock" onclick="check('cattle','breed_livestock')" >牛 &nbsp;&nbsp;
				<input type="checkbox" id="sheep" name="breedLivestock" onclick="check('sheep','breed_livestock')">羊 &nbsp;&nbsp;
			<li class="clearfix"></li>
		</ul>

<%--		<input type="button" value="新增" onclick="createRow()">&nbsp;&nbsp;--%>
<%--		<input type="button" value="删除" onclick="delRow()"><br><br>--%>

		<tr>
			<th style="text-align:center;"  class="btbg font-center titfont" rowspan="2">序号</th>
			<th style="text-align:center;"  class="btbg font-center titfont"  id="breed_livestock" rowspan="2">养殖畜种</th>
			<th style="text-align:center;" colspan="2"  class="btbg font-center titfont">上一年规模(头、只、羽)</th>
		</tr>
		<tr>
			<th style="text-align:center;" class="btbg font-center">总存栏</th>
			<th style="text-align:center;" class="btbg font-center">能繁母畜存栏</th>
			<th style="text-align:center;" class="btbg font-center">出栏量</th>
			<th ><a href="javascript:createRow()">新增</a></th>
		</tr>

		</thead>
		<tbody>

		<c:forEach items="${page.list}" var="farmClass" varStatus="vs" >
		<tr>
			<td>
					${vs.index+1}
			</td>
			<input type="hidden" name="farmClass.list[${vs.index}].id" class="per-id" value="${farmClass.id}"/>

<%--			<td>${farmClass.breedLivestock}</td>--%>
<%--			<td>${farmClass.scope}</td>--%>
<%--			<td>${farmClass.totalInventory}</td>--%>
<%--			<td>${farmClass.breeding_stock}</td>--%>
<%--			<td>${farmClass.quantityOfSlaughter}</td>--%>

			<td><input type="text" name="farmClass.list[${vs.index}].breedLivestock" class="input-xlarge per-breedLivestock"value="${farmClass.breedLivestock}"/></td>

			<td><input type="text" name="farmClass.list[${vs.index}].totalInventory" class="input-xlarge per-totalInventory"value="${farmClass.totalInventory}"/></td>
			<td><input type="text" name="farmClass.list[${vs.index}].breedingStock" class="input-xlarge per-breedingStock" value="${farmClass.breedingStock}"/></td>
			<td><input type="text" name="farmClass.list[${vs.index}].quantityOfSlaughter" class="input-xlarge per-quantityOfSlaughter" value="${farmClass.quantityOfSlaughter}"/></td>

			<td><a href="javascript:;" onclick="delRow(this)">删除</a></td>

		</tr>
		</c:forEach>
		</tbody>
	</table>

		<div class="form-actions">
			<div class="controls"><div class="controls">
			<shiro:hasPermission name="test2:farm:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
			</div></div>
		</div>
	</form:form>
</body>
</html>


